import { defineConfig, loadEnv } from "vite";
import vue from '@vitejs/plugin-vue'
import path from 'path'
// svg
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// 按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/

export default defineConfig(({ mode }) => {
  let env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]',
      }),
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData:'@import "@/styles/global.scss";'
        }
      }
    },
    base: env.VITE_USER_NODE_ENV === 'production' ? './' : '/',
    server: {
      host: '0.0.0.0',
      port: 6888,
    },
    resolve: {
      alias: {
        "@": path.resolve("./src")
      }
    },
    build: {
      rollupOptions: {
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return "vendor";
          }
        },
      },
    },
  }
})
